

var str = `fjskfjsl fjkdsjfkls fjklsfjlsd127.0.0.1fjksldfjafjio jfk192.168.1.101sljfs fsdjfkldsfjsklfsklffjoijfoiaf
asfjs fed jfjf jf sdjfsi jfi jafis function  dd ( ) { }afjsdiajf iosa function abc(){} jfisjad fjsaiofjaoissf
addedfds`;
/*
正则练习,获取IP地址
str:需要过滤的字符串
return：返回获取到的匹配字符数组
*/
function getIp(str){
  let reg = /(((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))\.){3}((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))/g;
  let arr;
  let res = new Array();
  while ((arr = reg.exec(str)) !== null){
      res.push(arr[0]);
  }
  return res;
}






/**
正则练习，获取方法function xxx()，未考虑参数及方法体内容
str:需要过滤的字符串
return：返回获取到的匹配字符数组
*/

function getFunction(str){
  let reg = /function\s+[a-zA-Z_]\w*\s*(\(\s*\)\s*){1}\{\s*\}/g;
  let arr;
  let res = new Array();
  while ((arr = reg.exec(str)) !== null){
      res.push(arr[0]);
  }
  return res;
}
console.log(getIp(str));
console.log(getFunction(str));
